package com.dd.common.exception;


import com.dd.common.enums.ErrorEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 业务异常：用于主动抛出的可预期错误
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class BusinessException extends RuntimeException {
    private int code;
    private String message;


    /**
     * 根据错误枚举返回失败响应
     */
    public BusinessException(ErrorEnum error) {
        this.code = error.getCode();
        this.message = error.getMsg();
    }

    /**
     * 失败响应并允许覆盖消息
     */
    public BusinessException(ErrorEnum error, String msg) {
        this.code = error.getCode();
        this.message = msg != null ? msg : error.getMsg();
    }
}
